<?php

namespace app\admin\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;


//三方支付配置
class Smsconfig extends Base
{
    public  $model;

    public function __construct()
    {
        parent::__construct();

    }

    /**
     *  获取三方支付配置信息
     */
    public function index(){

        $data  = [];
        $payMenmt = Config::get("baseextend.smsPaySet");


        foreach($payMenmt as $k=>$v){
            $data[$v] = Config::get($v);
        }

        return sucessJson("查询成功",$data);


    }


    //修改支付的配置信息
    public function save(){

            $extra   = APP_PATH."extra/";//配置扩展数据
            $key = $this->key.EXT;

            $postArr = $this->payment;
            $filePath = $extra.$key;
            if(file_exists($filePath)){
                $payMenmt = Config::get($this->key);
                foreach ($payMenmt as $k=>&$v){
                      if(isset($postArr[$k])){
                                if(!empty($postArr[$k])){
                                    $v = trim($postArr[$k]);
                                }

                      }
                }

                $paymentString  = var_export($payMenmt,true);

                $paymentStringLast = "<?php\n\r return ".$paymentString."\n\r?>";
                $wirteFile = file_put_contents($filePath,$paymentStringLast);
                if($wirteFile){
                    return sucessJson("修改支付配置成功");
                }
                return failJson("修改支付配置失败");

            }
        return failJson("修改支付配置失败");
    }


}
